package cn.neusoft.edu.his.demo.controller;

import cn.neusoft.edu.his.demo.common.Result;
import cn.neusoft.edu.his.demo.mapper.NoticeMapper;
import cn.neusoft.edu.his.demo.po.Notice;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@CrossOrigin
@Api("NoticeControlloer相关的api")
@RestController
public class NoticeController {
    @Autowired
    NoticeMapper noticeMapper;
    @RequestMapping("/getNotice")
    public Result getNotice(){
        QueryWrapper<Notice> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("day");
        List<Notice> notices =noticeMapper.selectList(queryWrapper);
       return Result.ok(notices);
    }
    @RequestMapping("/getNoticeId")
    public Result getNoticeById(int noticeId){
        Notice notice1 = noticeMapper.selectById(noticeId);
        return Result.ok(notice1);
    }
    @RequestMapping("/updateNotice")
    public void updateNotice(Notice notice){
        int update = noticeMapper.updateById(notice);
    }
    @RequestMapping("/deleteNotice")
    public void deleteNotice(Notice notice){
        int delete = noticeMapper.deleteById(notice.getId());
    }
    @GetMapping("/addNotice")
    public void addNotice(Notice notice){
        Date date = new Date();
        SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd");
        notice.setDay(dateFormat.format(date));
        noticeMapper.insert(notice);
    }

    
}
